{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# make an array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "int[] myNum = {10, 20, 30, 40};"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myNum.length;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n"
     ]
    }
   ],
   "source": [
    "System.out.println(myNum[0]);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "20\n",
      "30\n",
      "40\n"
     ]
    }
   ],
   "source": [
    "for (int i : myNum) {\n",
    "  System.out.println(i);\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# make a list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "List<Integer> list = new ArrayList<>(Arrays.asList(1, 2, 3)); "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3]"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list.size()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list.add(4);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list.get(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list.set(3, -1);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, -1]"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Print all the permutation of length L using the elements of an array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [],
   "source": [
    "import java.io.*; \n",
    "  \n",
    "static void convert_To_Len_th_base(int n, int arr[], int len, int L) \n",
    "{ \n",
    "    // Sequence is of length L \n",
    "    for (int i = 0; i < L; i++)  \n",
    "    { \n",
    "        // Print the ith element \n",
    "        // of sequence \n",
    "        System.out.print(arr[n % len]); \n",
    "        n /= len; \n",
    "    } \n",
    "    System.out.println(); \n",
    "} \n",
    "  \n",
    "// Print all the permuataions \n",
    "static void print(int arr[], int len, int L) \n",
    "{ \n",
    "    // There can be (len)^l \n",
    "    // permutations \n",
    "    for (int i = 0;  \n",
    "             i < (int)Math.pow(len, L); i++)  \n",
    "    { \n",
    "        // Convert i to len th base \n",
    "        convert_To_Len_th_base(i, arr, len, L); \n",
    "    } \n",
    "} "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11\n",
      "21\n",
      "31\n",
      "12\n",
      "22\n",
      "32\n",
      "13\n",
      "23\n",
      "33\n"
     ]
    }
   ],
   "source": [
    "int arr[] = { 1, 2, 3 }; \n",
    "int len = arr.length; \n",
    "int L = 2; \n",
    "\n",
    "// function call \n",
    "print(arr, len, L); "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Print all the permutation of length L using the elements of a list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [],
   "source": [
    "import java.io.*; \n",
    "  \n",
    "void convert_To_Len_th_base(int n, List<Integer> arr, int len, int L) \n",
    "{ \n",
    "    // Sequence is of length L \n",
    "    for (int i = 0; i < L; i++)  \n",
    "    { \n",
    "        // Print the ith element of sequence \n",
    "        System.out.print(arr.get(n % len)); \n",
    "        System.out.print(\" \"); \n",
    "        n /= len; \n",
    "    } \n",
    "    System.out.println(); \n",
    "} \n",
    "  \n",
    "void permuataions(List<Integer> arr, int L) \n",
    "{ \n",
    "    // There can be (len)^l permutations \n",
    "    int len = arr.size();\n",
    "    for (int i = 0; i < (int)Math.pow(len, L); i++)  \n",
    "    { \n",
    "        // Convert i to len th base \n",
    "        convert_To_Len_th_base(i, arr, len, L); \n",
    "    } \n",
    "} "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, -1]"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 1 \n",
      "2 1 \n",
      "3 1 \n",
      "-1 1 \n",
      "1 2 \n",
      "2 2 \n",
      "3 2 \n",
      "-1 2 \n",
      "1 3 \n",
      "2 3 \n",
      "3 3 \n",
      "-1 3 \n",
      "1 -1 \n",
      "2 -1 \n",
      "3 -1 \n",
      "-1 -1 \n"
     ]
    }
   ],
   "source": [
    "permuataions(list, 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Java",
   "language": "java",
   "name": "java"
  },
  "language_info": {
   "codemirror_mode": "java",
   "file_extension": ".jshell",
   "mimetype": "text/x-java-source",
   "name": "Java",
   "pygments_lexer": "java",
   "version": "11.0.10+9-Ubuntu-0ubuntu1.20.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
